<template>
	<view class="home">
		<!-- 轮播图 -->
		<swiper  indicator-dots circular>
			<swiper-item v-for="item in swispers" :key = "item.goods_id">
				<image :src="item.image_src"></image>
			</swiper-item>
		</swiper>
		<!-- 导航条 -->
		<view class="nav">
			<view class="nav_item" @click="clickNav('/pages/goods/goods')">
				<!-- icon -->
				<view class="iconfont icon-ziyuan"></view>
				<!-- text -->
				<text>黑马商城</text>
			</view>
			
			<view class="nav_item">
				<!-- icon -->
				<view class="iconfont icon-guanyuwomen" @click="clickNav('/pages/contact/contact')"></view>
				<!-- text -->
				<text>联系我们</text>
			</view>
			
			<view class="nav_item">
				<!-- icon -->
				<view class="iconfont icon-tupian"></view>
				<!-- text -->
				<text>社区图片</text>
			</view>
			
			<view class="nav_item">
				<!-- icon -->
				<view class="iconfont icon-shipin"></view>
				<!-- text -->
				<text>学习视频</text>
			</view>
		</view>
		<!-- 推荐商品 -->
		<view class="hot_goods"> 
			<view class="tit">商品推荐</view>
			<!-- 商品列表 -->
			<goods-list :goods = goods></goods-list>
		</view>
	</view>
</template>

<script>
	import goodsList from '../../components/goods/goods';
	export default {
		data() {
			return {
				// 存放轮播图
				swispers:[],
				// 存放商品数据
				goods:[],
				// 导航栏数据
				navInfo:[]
			}
		},
		components:{
			'goods-list':goodsList
		},
		onLoad() {
			this.swisper();
			this.getHotGoods();
			this.getNav();
			
		},
		methods: {
		// 获取录播图数据
			async swisper(){
				console.log("获取录播图")
				const res = await this.$Myrequest({
					url:'/home/swiperdata'
					
				})
				this.swispers = res.data.message	
			},
			
			
			// 获取热门商品
			async getHotGoods(){
				console.log('获取热门商品数据')
				const res = await this.$Myrequest({
					url:'/goods/search'
				})
				this.goods = res.data.message.goods
				
			},
			// 获取导航栏图片和标题
			async getNav(){
				console.log("获取导航栏数据")
				const res = await this.$Myrequest({
					url: '/home/floordata'
				})
				this.navInfo = res.data.message
				
				
			},
			// 跳转函数
			clickNav(url){
				uni.navigateTo({
					url
				})
			}
		}	
	}
</script>

<style lang="scss">
	.home{
		swiper{
			width: 750rpx;
			height: 380rpx;
			image{
				width: 100%;
				height: 100%;
			}
		}
		
		.nav{
			display: flex;
			.nav_item{
				width:25%;
				text-align: center;
				view{
					width: 120rpx;
					height: 120rpx;
					background-color: #d81e06;
					border-radius: 60rpx;
					margin: 10rpx auto;
					line-height: 120rpx;
					color: white;
					font-size: 50rpx;
					.iconfont-tupian{
						font-size: 45rpx;
					}
				}
				text{
					font-size: 30rpx;
				}
			}
		}
		.hot_goods{
			background: #eee;
			overflow: hidden;
			.tit{
				height: 50px;
				line-height: 50px;
				letter-spacing: 20px;
				font-size: 40rpx;
				text-align: center;
				color: #d81e06;
				background: #FFFFFF;
				margin: 5px 0;
			}
			
			
		}
	}
	
	
	
</style>
